package system

import (
	"encoding/json"
	"ltbz/cultural_tourism_api/controllers"
	"ltbz/cultural_tourism_api/models"
	"ltbz/cultural_tourism_api/models/system"
)

type SysDataAuthController struct {
	controllers.BaseAuthController
}

// @Tags 系统模块
// @Title 数据权限保存
// @Description 数据权限保存
// @Param	request	body system.DataAuthSave true "type json string"
// @Success 200
// @router /data_auth/save [post]
func (this *SysDataAuthController) DataAuthSave() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()

	body := this.Ctx.Input.RequestBody
	if string(body) == "" {
		br.Msg = "参数解析异常！"
		return
	}
	req := new(system.DataAuthSave)
	err := json.Unmarshal(body, &req)
	if err != nil {
		br.Msg = "参数解析异常！"
		br.ErrMsg = "参数解析失败，Err:" + err.Error()
		return
	}
	obj := new(system.SysUserDataAuth)
	err = obj.SaveSysUserDataAuth(req)
	if err != nil {
		br.Msg = "保存失败！"
		br.ErrMsg = "保存失败，Err:" + err.Error()
		return
	}
	br.Msg = "保存成功"
	br.Ret = 200
	return
}
